<template>
    <div>
        <el-row  type="flex" align="middle" justify="space-between">
            <el-input v-model="input" placeholder="输入关键字查询保险" style="margin-right: 15px"></el-input>
            <el-button icon="el-icon-search" circle @click="search"></el-button>
        </el-row>
        <br><br><br>
        <el-row  type="flex" align="middle" justify="space-between">
            <el-col :span="7" v-for="(o, index) in this.carcontent.length" :key="o" :offset="index > 0 ? 2 : 0">
                <el-card :body-style="{ padding: '0px' }">
                    <img :src="img[o%3]" class="image" alt="图片无法加载">
                    <div style="padding: 14px;">
                        <span>{{carcontent[o-1].comName}}</span>
                        <div class="bottom clearfix">
                            <time class="time">买保险就来找我</time>
                            <el-button type="text" class="button" @click="toCarComponent(carcontent[o-1])">买意外险</el-button>
                        </div>
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
export default {
    name: "accidentinsurance",
    data() {
        return {
            input:'',
            carcontent:[],
            img:[
                "http://qzq53lezl.hn-bkt.clouddn.com/yiwai1.jpg",
                "http://qzq53lezl.hn-bkt.clouddn.com/yiwai2.jpg",
                "http://qzq53lezl.hn-bkt.clouddn.com/yiwai3.jpg",
                "http://qzq53lezl.hn-bkt.clouddn.com/yiwai4.jpg"
            ]
        }
    },
    created() {
        this.getList();
    },
    methods : {
        toCarComponent:function (o) {
            console.log(o.id);
            this.$store.state.insuranceid = o.id;
            this.$store.state.subject = o.comName;
            this.$router.push("/home/accident")
        },
        getList(){
            var vm = this;
            this.axios({
                url: '/myapi/user/combined/listCombined/意外险',
                method: 'get'
            }).then(function (response) {
                if(response.data.success === true){
                    vm.carcontent = response.data.content;
                    console.log(vm.carcontent);
                }
                else {
                    console.log(response.data);
                    vm.$message.error('获取列表失败');
                }
            });
        },
        search(){
            ///user/combined/listCom/A
            var vm = this;
            this.axios({
                url: '/myapi/user/combined/listCom/'+vm.input,
                method: 'get'
            }).then(function (response) {
                if(response.data.success === true){
                    vm.carcontent = [];
                    let cars = response.data.content;
                    for(var j = 0,len = cars.length; j < len; j++){
                        if(cars[j].type === '意外险'){
                            vm.carcontent.push(cars[j]);
                        }
                    }
                    //vm.carcontent = response.data.content;
                }
                else {
                    vm.$message.error('失败');
                }
            });
        }
    }
}
</script>

<style scoped>
.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
}

.time {
    font-size: 13px;
    color: #999;
}

.bottom {
    margin-top: 13px;
    line-height: 12px;
}

.button {
    padding: 0;
    float: right;
}

.image {
    width: 100%;
    display: block;
}

.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}
</style>
